import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;


public class CreateXML {
	
	public static void main(String[] args) throws IOException {
		Document doc=DocumentHelper.createDocument();
		Element root=doc.addElement("root");
		Element person=root.addElement("person");
		Element name=person.addElement("name");
		name.addAttribute("name", "name");  //添加属性  
		name.addText("xiao");  //添加内容
		
		XMLWriter xmlWriter = new XMLWriter(); 
		xmlWriter.write(doc);
		
//		//读取文件   
//		FileWriter fileWriter = null;
//		try {
//			fileWriter = new FileWriter("c:/create.xml");
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}  
//		//创建写文件方法   
//		XMLWriter xmlWriter = new XMLWriter(fileWriter);   
//		   //写入文件   
//		xmlWriter.write(doc);   

	}


}
